using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;

namespace ModWatch
{

	/// <summary>
	/// Provides data for the <see cref="ModWatch.ModWatchExtenderBase.GettingScriptReferences"/>
	/// event of a <see cref="ModWatch.ModWatchExtenderBase"/>.
	/// </summary>
	public class ScriptReferencesEventArgs : EventArgs
	{

		#region Variables

		/// <summary>
		/// A collection of <see cref="System.Web.UI.ScriptReference"/>
		/// objects to be returned by the <see cref="ModWatch.ModWatchExtenderBase"/>
		/// </summary>
		private List<ScriptReference> _scriptReferences;

		/// <summary>
		/// The <see cref="System.Web.UI.Page"/> that is currently
		/// being processed.
		/// </summary>
		private Page _page;

		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="ModWatch.ScriptReferencesEventArgs"/> class.
		/// </summary>
		/// <param name="Page">
		/// The <see cref="System.Web.UI.Page"/> that is currently
		/// being processed.
		/// </param>
		public ScriptReferencesEventArgs(Page Page)
			: base()
		{
			_scriptReferences = new List<ScriptReference>();
			_page = Page;
		}

		#endregion

		#region Public Methods

		/// <summary>
		/// Registers a <see cref="System.Web.UI.ScriptReference"/> object
		/// to be used by the <see cref="ModWatch.ModWatchExtenderBase"/>.
		/// </summary>
		/// <param name="ScriptReference">
		/// The <see cref="System.Web.UI.ScriptReference"/> object to be registered.
		/// </param>
		public void AddScriptReference(ScriptReference ScriptReference)
		{
			_scriptReferences.Add(ScriptReference);
		}

		/// <summary>
		/// Registers a <see cref="System.Web.UI.ScriptReference"/> object
		/// that should be retrieved from a web resource.
		/// </summary>
		/// <param name="Type">The <see cref="System.Type"/> of the resource.</param>
		/// <param name="ResourceName">The fully qualified name of the resource in the assembly.</param>
		public void AddWebResourceScriptReference(Type Type, string ResourceName)
		{
			ScriptReference sr = new ScriptReference();
			sr.Path = _page.ClientScript.GetWebResourceUrl(Type, ResourceName);
			AddScriptReference(sr);
		}

		#endregion

		#region Internal Methods

		/// <summary>
		/// Registers a <see cref="System.Web.UI.ScriptReference"/> object that
		/// should be retrieved from a web resource within the ModWatch assembly.
		/// </summary>
		/// <param name="ResourceName">The fully qualified name of the resource in the assembly.</param>
		internal void AddWebResourceScriptReference(string ResourceName)
		{
			AddWebResourceScriptReference(typeof(IModWatcher), ResourceName);
		}

		/// <summary>
		/// Returns a collection of <see cref="System.Web.UI.ScriptReference"/>
		/// objects to be used by the <see cref="ModWatch.ModWatchExtenderBase"/>
		/// </summary>
		/// <returns></returns>
		internal IEnumerable<ScriptReference> GetScriptReferences()
		{
			return _scriptReferences;
		}

		#endregion

	}

}
